package com.jzo2o.health.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.jzo2o.health.model.excel.ReservationImportData;
import com.jzo2o.health.service.IReservationBatchSettingService;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;


@Slf4j
public class uploadListener implements ReadListener<ReservationImportData> {

    private IReservationBatchSettingService reservationBatchSettingService;

    private List<ReservationImportData> reservationImportDataList = new ArrayList<>();

    public uploadListener(IReservationBatchSettingService reservationBatchSettingService){
        this.reservationBatchSettingService=reservationBatchSettingService;
    }
    @Override
    public void invoke(ReservationImportData reservationImportData, AnalysisContext analysisContext) {
        log.info("读取到一条数据{}",reservationImportData);
        reservationImportDataList.add(reservationImportData);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        log.info("共读取{}条预约记录", reservationImportDataList.size());
        reservationBatchSettingService.doImport(reservationImportDataList);
    }
}
